package com.tangye.massageshop.controller;

import com.alibaba.fastjson.JSON;
import com.tangye.massageshop.entity.PackageEntity;
import com.tangye.massageshop.entity.UserEntity;
import com.tangye.massageshop.service.PackageService;
import com.tangye.massageshop.util.Result;
import com.tangye.massageshop.util.ThreadLocalUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Log4j2
@RestController
@RequestMapping("/package")
public class PackageController {

    @Resource
    private PackageService packageService;

    @PostMapping("/queryPackagePage")
    public Result<List<PackageEntity>> queryPackagePage(PackageEntity packageEntity) {
        log.info("入参：{}",JSON.toJSONString(packageEntity));
        UserEntity userSession = ThreadLocalUtil.get();
        packageEntity.setCompanyId(userSession.getCompanyId());
        List<PackageEntity> packageEntities = packageService.queryVarietyListPage(packageEntity);
        log.info("反参：{}",JSON.toJSONString(packageEntities));
        return Result.success(packageEntities);
    }

    @PostMapping("/addPackage")
    public Result<String> addPackage(@Validated PackageEntity packageEntity) {
        packageService.add(packageEntity);
        return Result.ok();
    }

    @PostMapping("/updatePackage")
    public Result<String> updatePackage(PackageEntity packageEntity) {
        packageService.update(packageEntity);
        return Result.ok();
    }






}
